//index.js
//获取应用实例
const app = getApp()
let Axios = require('../../common/js/ajax.js');
let Mtils = require('../../common/js/Mtils.min.js');
Mtils = Mtils.Mtils
var page = 1;
var switch_p = true
Page({
	data: {
		openid: '',
		nickName: '',
		avatarUrl: '',
		curentNav: 2, //当前导航
		order_id: 0,
		logI: {}
	},
	//事件处理函数
	onLoad: function(e) {
		var _this = this;
 		this.load = this.selectComponent("#loading");
		this.uid = app.globalData.uid || ''
		this.Md5 = Mtils.security.hex_md5(this.uid) + app.globalData.secret;
		this.Md5 = Mtils.security.hex_md5(this.Md5);
		this.timesp = Mtils.now();
		_this.setData({
			order_id: e.id
		})
		Axios.post(app.globalData.baseUrl + 'App/Store/Order/get_logistics', {
			uid: this.uid,
			time: this.timesp,
			sign: this.Md5,
			order_id:this.data.order_id
		}, (res) => {
			console.log(res)
			if (res.status == 1) {
				var data = res.info
				_this.setData({
					logI: data
				})
				_this.load.loadIng()
			} else {
				_this.showModal(res)
			}
		})
		if (app.globalData.nickName && app.globalData.avatarUrl) {
			this.setData({
				nickName: app.globalData.nickName,
				avatarUrl: app.globalData.avatarUrl
			})
		}
	},
	onReady: function() {
		wx.setNavigationBarTitle({
			title: '物流详情'
		})
	},
	preventTouchMove: function() {

	},
	showModal: function(error) {
		wx.showModal({
			content: error.msg,
			showCancel: false,
		})
	},
	handleDelTap: function(e) { //一键删除
		var _this = this;
		var index = e.currentTarget.dataset.index
		var id = e.currentTarget.dataset.id
		var list = this.data.list;
		var value = this.data.list[index].value;
		var len = value.length;
		Axios.post(app.globalData.baseUrl + 'App/Store/Goods/store_del_goods', {
			uid: this.uid,
			time: this.timesp,
			sign: this.Md5,
			store_id: this.data.store_id,
			goods_id: id
		}, (res) => {
			console.log(res)
			if (res.status == 1) {
				var data = res.info
				if (len > 1) {
					value.forEach(function(item, key) {
						if (item.id == id) {
							value.splice(key, 1)
							_this.setData({
								['list[' + index + '].value']: value
							})
						}
					})
				} else {
					list.splice(index, 1)
					_this.setData({
						list: list
					})
				}
			} else {
				_this.showModal(res)
			}
		})
	},
	handleClearTap: function(e) { //清除举报
		var _this = this;
		var index = e.currentTarget.dataset.index
		var id = e.currentTarget.dataset.id
		var list = this.data.list;
		var value = this.data.list[index].value;
		var len = value.length;
		Axios.post(app.globalData.baseUrl + 'App/Store/Goods/clear_report', {
			uid: this.uid,
			time: this.timesp,
			sign: this.Md5,
			store_id: this.data.store_id,
			goods_id: id
		}, (res) => {
			console.log(res)
			if (res.status == 1) {
				var data = res.info
				if (len > 1) {
					value.forEach(function(item, key) {
						if (item.id == id) {
							value.splice(key, 1)
							_this.setData({
								['list[' + index + '].value']: value
							})
						}
					})
				} else {
					list.splice(index, 1)
					_this.setData({
						list: list
					})
				}

			} else {
				_this.showModal(res)
			}
		})
	}
})
